import { httpGet, httpPost, httpPut, httpDel } from "@/appBase/request";
import { toData, toPageData, toPageQueryParam } from "@/appBase/utils";
import config from '@/config';

/**
 * 下载文件url
 */
export const commonDownload = '/common/download';

/**
 * 删除分类
 * @param {Object} params 
 * @param {String} params.id 
 * @returns 
 */
export function delCategoryTreeNode(params) {
    return httpDel(`/common/category/${params.id}`).then((result) => toData(result));
}

/**
 * 交换排序分类排序
 * @param {Object} params 
 * @param {String} params.maxId 业务Id(排序号大的)
 * @param {String} params.maxSortNo 排序号大的
 * @param {String} params.minId 业务Id(排序号小的)
 * @param {String} params.minSortNo 排序号小的
 * 
 * @returns 
 */
export function updateCategoryTreeNodeSort(params) {
    return httpPut(`/common/category/sort`,params).then((result) => toData(result));
}

/**
 * 通用文件上传
 * @param {Object} params
 * @param {String} params.file 文件
 * @param {String} params.resourceBizType 文件资源类型  
 */
export function filesUpload(params) {
    const t = parseInt(Math.random()*1000);
    const result = {"code":200,"msg":"操作成功","data":{"fileId":"1631205526921646082","fileUrl":"http://116.63.139.60:9006/common/file/1631205526921646082.txt","uploadTime":"2023-03-02 16:11:18"}}
    return Promise.resolve(toData(result));
    // return httpPost(`/common/files-upload?_t=${t}`, params).then((result) => toData(result));
}

/**
 * 通用上传
 * @returns 
 */
export function basePost(url, param) {
    const result = {"code":200,"msg":"操作成功","data":{"fileId":"1631205526921646082","fileUrl":"http://116.63.139.60:9006/common/file/1631205526921646082.txt","uploadTime":"2023-03-02 16:11:18"}}
    return Promise.resolve(toData(result));
    // return httpPost(url, param).then((result) => toData(result));
}

// 文件在线预览
export function onlinePreview(url) {
    return `${config.fileViewRoot}/onlinePreview?url=${url}`;
}
